
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:184,
  },

  getPhoneNumber(e) {
    var _ = this;
    var area = _.data.area;
    var agent = _.data.agent;
    var flag = _.data.flag;
    if (flag) {
      wx.cloud.callFunction({
        name: 'getMobile',
        data: {
          weRunData: wx.cloud.CloudID(e.detail.cloudID),
        }
      }).then(res => {
        wx.setStorageSync('ywkphone', res.result)
        _.setData({
          mobile: res.result,
        })
        wx.request({
          url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
          method: 'POST',
          data: {
            activeId: 42,
            mobile: res.result,
            areaCode: _.data.area,
            agent: _.data.agent,
            pageId: _.data.page
          },
          success: res => {

          }
        })
        wx.request({ //发送请求
          url: "https://zg99.offcn.com/index/kanjia/register/?actid=47470&callback=?",
          data: {
            phone: res.result,
            isagree: true,
            fenxiao: area,
            agent: agent
          }, //接收参数
          success(res) { //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            };
            console.log(theJson)
            
              wx.navigateTo({
                url: '../zl/zl?area=' + _.data.area + '&agent=' + _.data.agent + '&page=' + _.data.page,
              })
            

          }
        })
      }).catch(err => {
        console.error(err);
      });
    } else {
      wx.showToast({
        title: '请先勾选隐私协议！',
        icon: 'none'
      })
    }

  },

  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../../agreement/agreement',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var _ = this;
    console.log(options)
    wx.setStorageSync('area', options.area)
    wx.setStorageSync('agent', options.agent)
    wx.setStorageSync('page', options.page)
    
    _.setData({
      area: options.area,
      agent: options.agent,
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
    var phone = wx.getStorageSync('ywkphone')
    if(phone){
      wx.redirectTo({
        url: '../zl/zl?area=' + _.data.area + '&agent=' + _.data.agent + '&page=' + _.data.page,
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})